/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.user.controller.assembler;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Objects;
import net.siufung.core.utils.CopyUtil;
import net.siufung.market.base.user.mapper.entity.UserDetail;
import net.siufung.market.base.user.controller.model.vo.UserDetailVo;

/**
 *
 * 系统用户详细 持久层展示层组装器
 *
 * @author 陈建峰
 * @date 2023-02-06 23:25:52
 * @since v1.0.0
 */
public class UserDetailAssembler {

    /**
     * UserDetail 转换成 UserDetailVo
     * @param userDetail 数据库实体
     * @return UserDetailVo 视图
     */
    public static UserDetailVo from(UserDetail userDetail){
        if(!Objects.isNull(userDetail)){
            UserDetailVo userDetailVo = new UserDetailVo();
            CopyUtil.copyProperties(userDetail, userDetailVo);
            return userDetailVo;
        }
        return null;
    }

    /**
     * UserDetailList 转换成 UserDetailVoList
     * @param userDetailList 数据库实体集合
     * @return List<UserDetailVo> 视图集合
     */
    public static List<UserDetailVo> fromList(List<UserDetail> userDetailList){
        List<UserDetailVo> userDetailVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(userDetailList)){
            UserDetailVo userDetailVo;
            for (UserDetail userDetail: userDetailList) {
                userDetailVo = new UserDetailVo();
                CopyUtil.copyProperties(userDetail, userDetailVo);
                userDetailVoList.add(userDetailVo);
            }
        }
        return userDetailVoList;
    }
}

